Flash Article

Building a Tip of the Day Application (Part 3): Submitting Tips to the Web Service


Table of Contents

  1. Introduction
  2. Binding Data to the Submit a Tip Interface
  3. Formatting Dates
  4. Building the Calendar Browse Interface
  5. Searching for Tips
  6. Displaying a Tip from the Search Results
  7. Applying a Style Sheet

Building the Calendar Browse Interface

Integrating the DateChooser (calendar) component is a fairly simple proposition after you've built the dateFormat function. When a user clicks a calendar date, the DateChooser code throws a change event, which you can easily trap.

When a user clicks a date, you want to send her to the tip screen and show her the tip for the day she chose.

  1. On the search screen, select the DateChooser instance and open the Behaviors panel.
  2. Click the Add Behavior button and select Screen > Go to Slide from the contextual menu.
  3. In the Select Screen dialog box, select the tip screen and click the OK button.
  4. In the Behaviors panel, change the event from scroll to change. Now when a user clicks a date, the screen will change.

Next, you need to set the value of the tipdate_str in the DataHolder to the value of the currently selected date. Here's why: To get the getTipByDate function to work in the web service, you need to pass it a date. The date parameter that’s sent to the web service is bound to the dataHolder_dh.tipdate_str parameter. Therefore, before sending the user back to the tip page, you have to update this date string in the DataHolder component to the date that the user clicked on the calendar. Also, when the user clicks a date, the date is passed as an ActionScript date object that you need to convert to MM/DD/YYYY format before you can send it to the web service.

  1. Select the DataChooser instance on the search screen. Open the Actions panel and add the following line of code above the // GoTo Screen comment.

    this._parent._parent._parent.dataHolder_dh.tipdate_str = this._parent._parent._parent.dateFormat(this.selectedDate);

    This code sets the value of tipdate_str in the dataHolder_dh instance to the value of the currently selected date and formats the date using the custom formatting function. Note that since you defined the function on the presentation screen, you have to use dot syntax to reference the function just as you would for a component instance.

  2. Enter the following code above the code you added in step 1.

    if (this.selectedDate == undefined) {
    		return;
    	}
    

    The code checks if the current selectedDate is undefined. If no date is defined, the rest of the code (including setting the value of the tipdate_str property in the DataHolder and the Go to Slide behavior) is skipped.

    Why do you need to do this? When working with the DateChooser component, if a user clicks a date to select it, then clicks the same date again, it becomes deselected. This leaves the value of selectedDate undefined. However, the Tip of the Day code would still trigger the change event.

    To work around this, you're using the code in Step 2 to check the value of selectedDate to see if it is defined or not. If the value hasn’t been defined, then the user has most likely selected the same date twice and therefore you can disregard the click event.